﻿namespace PersonalWebsite.Core.Result;

public class ApiResult
{

    public BusinessEnum Code { get; init; }

    public string Message { get; init; }

    public ApiResult(BusinessEnum code)
    {
        Code = code;
    }

    public ApiResult(BusinessEnum code, string message)
    {
        Code = code;
        Message = message;
    }

    public static ApiResult Success() => new ApiResult(BusinessEnum.Success);

    public static ApiResult Success(string message) => new ApiResult(BusinessEnum.Success, message);

    public static ApiResult Failed(string message = "操作失败") => new ApiResult(BusinessEnum.Failed, message);

}

public class ApiResult<T> : ApiResult
{
    public ApiResult(BusinessEnum code, string message, T date) : base(code, message)
    {
        Message = message;
        Data = date;
    }

    public T Data { get; init; }

    public static ApiResult<T> Success(string message, T data) => new ApiResult<T>(BusinessEnum.Success, message, data);

    public static ApiResult<T> Success(T data) => new ApiResult<T>(BusinessEnum.Success, "操作成功", data);
}
